package com.jic.market.mapper.skill;

import com.jic.common.base.vo.RestResult;
import com.jic.market.entity.skill.SkillActivityTimeConfig;

import com.jic.market.request.rest.seckill.QueryProcessingGoodsListPageRequest;
import com.jic.market.response.rest.seckill.QueryGoodsListResponse;
import com.jic.market.response.rest.seckill.SeckillTimeListResponse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 秒杀基础信息时间间隔配置表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-12 04:47:15
 */
@Repository
public interface SkillActivityTimeConfigMapper {

    long insert(SkillActivityTimeConfig skillActivityTimeConfig);

    long delete(@Param("promotionId") String promotionId);

    long update(SkillActivityTimeConfig skillActivityTimeConfig);

    SkillActivityTimeConfig queryByPrimaryKey(Long id);

    List<SkillActivityTimeConfig> query(SkillActivityTimeConfig skillActivityTimeConfig);

    List<SkillActivityTimeConfig> queryPage(@Param("startIndex") int startIndex, @Param("limit") int limit, @Param("skillActivityTimeConfig") SkillActivityTimeConfig skillActivityTimeConfig);

    long queryPageCount(SkillActivityTimeConfig skillActivityTimeConfig);

    @Select("select * from market_skill_activity_time_config where promotion_id=#{promotionId} and delete_flag='0'")
    List<SkillActivityTimeConfig> queryByPromotionId(@Param("promotionId")String promotionId);

    @Select("select time_id from market_skill_activity_time_config where promotion_id=#{promotionId} and delete_flag='0'")
    List<String> queryTimeIdByPromotionId(@Param("promotionId")String promotionId);

    @Update("update market_skill_activity_time_config set start_time_of_date=#{startTimeOfDate}," +
            "end_time_of_date=#{endTimeOfDate} where promotion_id=#{promotionId} and time_id=#{timeId} and delete_flag='0'")
    long updateTimeByPromotionId(@Param("startTimeOfDate")String startTimeOfDate,
                                 @Param("endTimeOfDate")String endTimeOfDate,
                                 @Param("promotionId")String promotionId,
                                 @Param("timeId")String timeId);


    @Select("select time_id from market_skill_activity_time_config where promotion_id=#{promotionId} " +
            "and start_time_of_date=#{startTimeOfDate},end_time_of_date=#{endTimeOfDate} " +
            "and delete_flag='0'")
    String queryTimeIdByPromotionIdAndDate(@Param("promotionId")String promotionId,
                                           @Param("startTimeOfDate")String startTimeOfDate,
                                           @Param("endTimeOfDate")String endTimeOfDate);

    @Select("select * from market_skill_activity_time_config where promotion_id=#{promotionId} " +
            "and time_id=#{timeId} and delete_flag='0'")
    SkillActivityTimeConfig queryTimeConfigByPromotionIdAndTimeId(@Param("promotionId")String promotionId,
                                                                  @Param("timeId")String timeId);


    @Update("update market_skill_activity_time_config set delete_flag='1' where promotion_id=#{promotionId} " +
            " and time_id=#{timeId}")
    long deleteByPromotionIdAndTimeId(@Param("promotionId")String promotionId,
                                      @Param("timeId")String timeId);

    List<SeckillTimeListResponse> queryDaySeckillTime();

    int insertBatch(@Param("items") List<SkillActivityTimeConfig> items);

    List<QueryGoodsListResponse> queryProcessingGoodsListPage(@Param("request") QueryProcessingGoodsListPageRequest request, @Param("timeIdStr") String timeIdStr);

    Long queryProcessingGoodsListPageCount(@Param("timeIdStr") String timeIdStr);

    List<SkillActivityTimeConfig> queryProcessingTimeList();

    List<SkillActivityTimeConfig> queryNoStartTimeList();

    List<SkillActivityTimeConfig> queryEndTimeList();


}